import pymisp
from androidsandbox.utils import logger, Utils, CFG
from datetime import datetime
from pathlib import Path

misp = Utils.init_misp(CFG['misp']['url'], CFG['misp']['key'])
res = misp.search(controller='events',
            tags=misp.build_complex_query(and_parameters=
                                          ['secheart:source="VirusShare_APK_2019"',
                                           'secheart:analysis="ui-testing"']),
            include_correlations=False,
            with_attachments=False,
            metadata=True,
                  timestamp=datetime(2020, 9, 28, 3, 2, 0))
print(f'{len(res)} events found')
for event in res:
    event_uuid = event['Event']['uuid']
    misp.untag(event_uuid, 'secheart:analysis="ui-testing"')
    print(f'{event_uuid} done')
print('all done')